﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class DailyConfig extends Object
    {
        private var _dailyDic:Dictionary;
        private var _activityDic:Dictionary;
        private static var _instance:DailyConfig;

        public function DailyConfig()
        {
            this.initDaily();
            this.initActivity();
            return;
        }// end function

        private function initDaily() : void
        {
            var _loc_2:Object = null;
            var _loc_3:TDailyViewConfig = null;
            this._dailyDic = new Dictionary();
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_daily_view_config.json");
            for each (_loc_2 in _loc_1)
            {
                
                _loc_3 = new TDailyViewConfig();
                ClassTypesUtil.copyValue(_loc_3, _loc_2);
                this._dailyDic[_loc_3.id] = _loc_3;
            }
            return;
        }// end function

        private function initActivity() : void
        {
            var _loc_2:Object = null;
            var _loc_3:TActivityConfig = null;
            this._activityDic = new Dictionary();
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_activity_config.json");
            for each (_loc_2 in _loc_1)
            {
                
                _loc_3 = new TActivityConfig();
                ClassTypesUtil.copyValue(_loc_3, _loc_2);
                this._activityDic[_loc_3.id] = _loc_3;
            }
            return;
        }// end function

        public function getDailyItem(param1:int) : TDailyViewConfig
        {
            return this._dailyDic[param1] as TDailyViewConfig;
        }// end function

        public function getActivityItem(param1:int) : TActivityConfig
        {
            return this._activityDic[param1] as TActivityConfig;
        }// end function

        public function getWeekTimeById(param1:int) : int
        {
            var _loc_2:int = 0;
            var _loc_3:* = this.getDailyItem(param1);
            if (_loc_3.openWeekDay)
            {
                _loc_2 = _loc_3.openWeekDay.split("#").length;
            }
            else if (_loc_3.normalOpenDt)
            {
                if (_loc_3.normalOpenDt.indexOf("&"))
                {
                    _loc_2 = _loc_3.normalOpenDt.split("&").length * 7;
                }
                else
                {
                    _loc_2 = 7;
                }
            }
            else
            {
                _loc_2 = int(_loc_3.times) * 7;
            }
            return _loc_2;
        }// end function

        public function get allActivityData() : Array
        {
            var _loc_2:TActivityConfig = null;
            var _loc_1:Array = [];
            for each (_loc_2 in this._activityDic)
            {
                
                _loc_1.push(_loc_2);
            }
            _loc_1.sortOn("id", Array.NUMERIC);
            return _loc_1;
        }// end function

        public function get allGuildData() : Array
        {
            var _loc_2:TDailyViewConfig = null;
            var _loc_1:Array = [];
            for each (_loc_2 in this._dailyDic)
            {
                
                if (_loc_2.guildActivity > 0)
                {
                    _loc_1.push(_loc_2);
                }
            }
            return _loc_1;
        }// end function

        public function get allDailyData() : Dictionary
        {
            return this._dailyDic;
        }// end function

        public static function get instance() : DailyConfig
        {
            if (!_instance)
            {
                _instance = new DailyConfig;
            }
            return _instance;
        }// end function

    }
}
